﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zor_DAL;
using Zor_Modes;
using Zor_Tools;

namespace Zor_Bll
{
    /// <summary>
    /// 商铺管理
    /// create by light at 20174.5
    /// </summary>

    public class Zor_Shops_Bll<T> where T : class
    {
        /// <summary>
        /// 获取 商铺列表
        /// </summary>
        /// <param name="index">页码</param>
        /// <param name="TotalCount">返回值</param>
        /// <returns></returns>
        public static List<T> GetPageList(int index, out int TotalCount, string where)
        {
            // where = "";
            return PagerHelp<T>.GetPagerList(index, "[V_Zor_Hous]", "Hs_CreateTime desc ", out TotalCount, where);
        }

        /// <summary>
        ///  商铺管理-修改
        /// </summary>
        /// <param name="hous">楼宇对象</param>
        /// <returns>应答</returns>
        public static BaseAnswer UpdateHous(Zor_Hous hous, Zor_NaturalPerson naturalPerson)
        {
            BaseAnswer bar = Zor_Hous_DAL<T>.UpdateHous(hous, naturalPerson);
            if (bar.AnswerType != BaseAnswer.Answers.Error)
                bar.AnswerMeg = bar.AnswerType == BaseAnswer.Answers.Succee ? "修改成功！" : "修改失败,请检查商铺名称是否重复！";
            return bar;
        }

        /// <summary>
        ///  商铺管理-新增
        /// </summary>
        /// <param name="hous">楼宇对象</param>
        /// <param name="flage">标识</param>
        /// <returns>执行结果</returns>
        public static BaseAnswer InsertHous(dynamic hous, int flage, Zor_NaturalPerson naturalPerson)
        {
            hous.Hs_CreateTime = TimeHelper.ToNowTimeStamp();
            hous.User_Id = RequestSession.GetSessionUser().User_Id;
            hous.Hs_Flage = flage;
            naturalPerson.NatPer_CreateName = RequestSession.GetSessionUser().User_Id;
            naturalPerson.NatPer_CreateTime = TimeHelper.ToNowTimeStamp();

            BaseAnswer bar = Zor_Hous_DAL<T>.InsertHous(hous, naturalPerson);
            if (bar.AnswerType != BaseAnswer.Answers.Error)
                bar.AnswerMeg = bar.AnswerType == BaseAnswer.Answers.Succee ? "增加成功！" : "新增失败，请检查名称是否重复！";
            return bar;
        }

        /// <summary>
        /// 租赁信息新增
        /// </summary>
        /// <param name="lease">房屋对象</param>
        /// <returns>执行结果</returns>
        public static BaseAnswer InsertHsLease(Zor_Lease lease, DateTime startTime, DateTime endTime)
        {
            BaseAnswer bar = Zor_Hous_DAL<T>.InsertHsLease(lease, startTime, endTime);
            if (bar.AnswerType != BaseAnswer.Answers.Error)
                bar.AnswerMeg = bar.AnswerType == BaseAnswer.Answers.Succee ? "租赁成功！" : "租赁失败，请检查该房屋是否已处于租赁状态！";
            return bar;
        }

        /// <summary>
        ///  商铺删除
        /// </summary>
        /// <param name="id">楼宇ID集合</param>
        /// <returns></returns>
        public static BaseAnswer DeleteHous(int[] id)
        {
            BaseAnswer bar = Zor_Hous_DAL<T>.DeleteHous(id);
            if (bar.AnswerType != BaseAnswer.Answers.Error)
                bar.AnswerMeg = bar.AnswerType == BaseAnswer.Answers.Succee ? "删除成功！" : "删除失败，请重试！";
            return bar;
        }

      
        /// <summary>
        /// 查询所有街道
        /// create light by 2017.3.27     
        /// </summary>
        /// <returns></returns>
        public static List<T> SelectBdName()
        {
            return Zor_Hous_DAL<T>.SelectBdName();
        }
        /// <summary>
        /// 查询所有门牌
        /// create light by 2017.3.28
        /// <param name="id">街道ID</param>
        /// </summary>
        /// <returns></returns>
        public static List<T> GetUimName(int Id)
        {
            return Zor_Hous_DAL<T>.GetUimName(Id);
        }

    }
}
